import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

class Score {
    private String name;
    private float score;

    public Score(String name, float score) {
        this.name = name;
        this.score = score;
    }

    public String getName() {
        return name;
    }

    public float getScore() {
        return score;
    }

    @Override
    public String toString() {
        return "Score{" +
                "name='" + name + '\'' +
                ", score=" + score +
                '}';
    }
}

class Student {
    private String name;
    private String sno;
    private ArrayList<Score> homeworkScores = new ArrayList<>();
    private ArrayList<Score> interactionScores = new ArrayList<>();
    private float examScore;

    public Student(String sno, String studentName) {
        this.sno = sno;
        this.name = studentName;
    }

    public String getName() {
        return name;
    }

    public String getSno() {
        return sno;
    }

    public ArrayList<Score> getHomeworkScores() {
        return homeworkScores;
    }

    public ArrayList<Score> getInteractionScores() {
        return interactionScores;
    }

    public float getExamScore() {
        return examScore;
    }

    public void setExamScore(float examScore) {
        this.examScore = examScore;
    }

    public void addHomeworkScore(Score score) {
        homeworkScores.add(score);
    }

    public void addInteractionScore(Score score) {
        interactionScores.add(score);
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", sno='" + sno + '\'' +
                ", homeworkScores=" + homeworkScores +
                ", interactionScores=" + interactionScores +
                '}';
    }
}

public class StudentMain {
    private static Map<String, Student> students = new HashMap<>();
    private static Scanner scanner = new Scanner(System.in);

    // 提取公共方法：获取或创建学生对象
    private static Student getOrCreateStudent(String sno, String studentName) {
        Student student = students.get(sno);
        if (student == null) {
            student = new Student(sno, studentName);
            students.put(sno, student);
        }
        return student;
    }

    // 统一处理成绩读取逻辑
    private static void readScores(String exitCommand, int scoreIndex, boolean isHomework, boolean isInteraction) {
        while (true) {
            String input = scanner.nextLine();
            if (input.equals(exitCommand)) {
                break;
            }
            String[] arr = input.split(",");
            String sno = arr[0];
            String studentName = arr[1];
            try {
                float score = Float.parseFloat(arr[scoreIndex]);
                Score scoreObj = new Score(arr[4], score);
                Student student = getOrCreateStudent(sno, studentName);
                if (isHomework) {
                    student.addHomeworkScore(scoreObj);
                } else if (isInteraction) {
                    student.addInteractionScore(scoreObj);
                }
            } catch (NumberFormatException e) {
                System.out.println("成绩格式错误，请输入有效的浮点数！");
            }
        }
    }

    // 读取并处理考核成绩
    private static void readExamScores() {
        while (true) {
            String input = scanner.nextLine();
            if (input.equals("exit3")) {
                break;
            }
            String[] parts = input.split(",");
            String sno = parts[0];
            String studentName = parts[1];
            try {
                float min = Float.parseFloat(parts[4]);
                min = Math.min(min, Float.parseFloat(parts[5]));
                min = Math.min(min, Float.parseFloat(parts[6]));
                min = Math.min(min, Float.parseFloat(parts[7]));
                min = Math.min(min, Float.parseFloat(parts[8]));
                Student student = getOrCreateStudent(sno, studentName);
                student.setExamScore(min);
            } catch (NumberFormatException e) {
                System.out.println("成绩格式错误，请输入有效的浮点数！");
            }
        }
    }

    // 查询并输出学生成绩信息
    private static void queryStudent(String id) {
        Student student = students.get(id);
        if (student != null) {
            System.out.println(student.getName());
            float sumHomeworkScore = 0;
            for (Score score : student.getHomeworkScores()) {
                sumHomeworkScore += score.getScore();
            }
            float avgHomeworkScore = sumHomeworkScore / student.getHomeworkScores().size();
            System.out.println("作业平均分：" + avgHomeworkScore);

            float maxInteractionScore = Float.MIN_VALUE;
            for (Score score : student.getInteractionScores()) {
                maxInteractionScore = Math.max(maxInteractionScore, score.getScore());
            }
            System.out.println("互动成绩最高分：" + maxInteractionScore);

            System.out.println("考核成绩最低分：" + student.getExamScore());
        } else {
            System.out.println("未找到该学号对应的学生信息！");
        }
    }

    public static void main(String[] args) {
        readScores("exit1", 5, true, false);
        readScores("exit2", 5, false, true);
        readExamScores();
        System.out.println("请输入要查询的学生学号：");
        String id = scanner.nextLine();
        queryStudent(id);
        scanner.close();
    }
}